home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / PowerClassQueryDevice / QueryDevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-25  |  2.1 KB  |  105 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        QueryDevice.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. /*
  13.  *  QueryDevice.c
  14.  *  © 1999 Apple Computer, Inc.
  15.  *
  16.  *  Sample showing the use of the USBPowerShim API
  17.  *  Comments: Tom Clark, tclark@apple.com
  18.  *  
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <USB.h>
  24. #include "PowerClass.h"
  25.  
  26. int main(void)
  27. {
  28. OSStatus                status = noErr;
  29. PowerDeviceDescriptor    device;
  30. UInt16                    x = 0;
  31. UInt32                    choice = 0;
  32. UInt32                    ref;
  33. UInt32                    collection;
  34. UInt32                    page;
  35. UInt32                    usage;
  36. SInt32                    value;
  37.     
  38.     device.reference = kNoDeviceRef;        // Prime the search
  39.     do
  40.     {
  41.         status = GetNextPowerDevice (&device);
  42.         if (noErr == status)
  43.         {
  44.             printf ("Device Found.  Reference: 0x%X\n", device.reference);
  45.         }    
  46.     } while (noErr == status);
  47.  
  48.  
  49.         printf ("\nDevice Reference To Query: ");
  50.         scanf ("%x", &ref);
  51.             
  52.     while (1)
  53.     {
  54.     
  55.         printf ("\n[1] Get Usage Data\n");
  56.         printf ("[2] Set Usage Data\n");
  57.         printf ("Choice: ");
  58.         scanf ("%d", &choice);
  59.         
  60.         switch (choice)
  61.         {
  62.             case (1):
  63.                 printf ("\nCollection: ");
  64.                 scanf ("%x", &collection);
  65.                 printf ("Usage Page: ");
  66.                 scanf ("%x", &page);
  67.                 printf ("Usage: ");
  68.                 scanf ("%x", &usage);
  69.                 status = USBPowerGetUsageData (ref, collection, page, usage, &value);    // Ask the shim for the info
  70.                 if (noErr == status)
  71.                     printf ("Value Returned: %d\n", value);
  72.                 else if (status == kUSBPending)    
  73.                 {
  74.                     status = USBPowerGetUsageData (ref, collection, page, usage, &value);    // Ask the shim for the info
  75.                     if (noErr == status)
  76.                         printf ("Value Returned: %d\n", value);
  77.                     else
  78.                         printf ("Error: %d\n", status);
  79.                 }        
  80.                 else
  81.                     printf ("Error: %d\n", status);
  82.                 break;    
  83.             case (2):
  84.                 printf ("\nCollection: ");
  85.                 scanf ("%x", &collection);
  86.                 printf ("Usage Page: ");
  87.                 scanf ("%x", &page);
  88.                 printf ("Usage: ");
  89.                 scanf ("%x", &usage);
  90.                 printf ("Value: ");
  91.                 scanf ("%d", &value);
  92.                 status = USBPowerSetUsageData (ref, collection, page, usage, value);    
  93.                 printf ("Status Returned: %d\n", status);
  94.                 break;    
  95.             default:
  96.                 break;
  97.         
  98.         }
  99.         
  100.     }        
  101.     
  102. return 0;
  103. }
  104.  
  105.